//
//  SKUDefultQuestionTBNewCellText.m
//  ZITHER
//
//  Created by weixin on 2018/9/20.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDefultQuestionTBNewCellText.h"

@implementation SKUDefultQuestionTBNewCellText

- (void)awakeFromNib {
    [super awakeFromNib];

//    self.backgroundColor = [UIColor redColor];
    [self setUI];
    [self setMasonry];
    
}

-(void)setUI{
    [self addSubview:self.viewBack];//边界图
//    [self addSubview:self.viewText];//内容
    [self addSubview:self.Cardenter];//→
    
    [self addSubview:self.labTakein];//接受报价
    [self addSubview:self.price];//价格
    [self.viewBack addSubview:self.MapImage];
    
//    [self addSubview:self.merchantImage];//商家头像
//    [self addSubview:self.merchantName];//商家名称
//    [self addSubview:self.scrollview];//图片滑动
}

-(void)setMasonry{
    
    [self.labTakein mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.left.equalTo(self).offset(35);
        make.height.mas_equalTo(20);
    }];
    
    [self.viewBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self).offset(-14);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    
    [self.Cardenter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.labTakein.mas_centerY).offset(0);
        make.right.equalTo(self).offset(-35);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(8);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labTakein.mas_bottom).offset(20);
        make.left.equalTo(self).offset(35);
    }];
    
    [self.MapImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.price.mas_bottom).offset(10);
        make.height.mas_equalTo(90);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self).offset(-14);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    
    
//    [self.viewText mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.price.mas_bottom).offset(5);
//        make.right.equalTo(self).offset(-35);
//        make.left.equalTo(self).offset(35);
//    }];

//    self.scrollview.backgroundColor = [UIColor randomColor];
//    [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.viewText.mas_bottom).offset(5);
////        make.width.mas_equalTo(kScreenW-70);
//        make.right.equalTo(self.Cardenter).offset(0);
//
//        //        make.right.equalTo(self).offset(-35);
//        make.left.equalTo(self).offset(35);
//        make.height.mas_equalTo(70);
//    }];
    
//    [self.merchantImage mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.scrollview.mas_bottom).offset(5);
//        make.right.equalTo(self).offset(-35);
//        make.height.width.mas_equalTo(30);
//        make.bottom.mas_equalTo(self).offset(-35);
//    }];
//
//    [self.merchantName mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.merchantImage.mas_centerY).offset(0);
//        make.right.equalTo(self.merchantImage.mas_left).offset(-5);
//    }];
//

}



/**
 
 -(void)setUI{
 [self addSubview:self.viewBack];//边界图
 [self addSubview:self.viewText];//内容
 [self addSubview:self.Cardenter];//→
 
 [self addSubview:self.labTakein];//接受报价
 [self addSubview:self.price];//价格
 
 [self addSubview:self.merchantImage];//商家头像
 [self addSubview:self.merchantName];//商家名称
 [self addSubview:self.scrollview];//图片滑动
 
 */

-(void)setModel:(skuDetailModel *)model{
    _model = model;
    
    NSString *str = [NSString stringWithFormat:@"已接受%@个报价",self.model.acceptPriceCount];
    self.labTakein.text = str;
    
    [self.MapImage sd_setImageWithURL:[NSURL URLWithString:[NSString getMapImageView:model.latitude markers:model.longitude]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        //        NSLog(@"map ==== %@ %@ ")
        self.MapImage.image = image.grayImage;//图片变灰
        
    }];
    
    if (![self.model.acceptPriceCount isEqualToString:@"0"]) {
        
        int priceInt = [self.model.acceptPrice intValue];
        NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
        moneyFormatter.positiveFormat = @"###,##0";
        NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
        self.price.text = [NSString stringWithFormat:@"¥ %@",formatString];
        
//    self.viewText.text = self.model.acceptSourceDesc;
//    self.merchantName.text = self.model.acceptBizNickName;
        
    NSString *pic = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.acceptBizPortrait];
//    [self.merchantImage sd_setImageWithURL:[NSURL URLWithString:pic]];

    [self setScrImage:self.model.acceptFileList];

        
//    [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.viewText.mas_bottom).offset(5);
//        make.height.mas_equalTo(70);
//    }];
//    [self.merchantImage mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(30);
//    }];
//    }else{
//        [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.viewText.mas_bottom).offset(-10);
//            make.height.mas_equalTo(0);
//        }];
//        [self.merchantImage mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.mas_equalTo(0);
//        }];
//
//        self.scrollview.hidden = YES;
    }
    
    //    [self setNeedsLayout];
}


-(void)setScrImage:(NSArray *)arr{
    
//    self.scrollview.hidden = NO;
    //    [self.scrollview addScrImage:arr imageHeight:70];

    
    
    
//    [self.scrollview addScrImage:arr];

    
    
//    [self.scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
//    self.scrollview.contentSize = CGSizeMake(arr.count*68+15,0);
//
//    for (int j = 0; j<arr.count; j++) {
//        UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+15,0, 60,60)];
//
//        [imageV setCornerRadiusWithRadius:5 isMasks:YES];
//        imageV.backgroundColor = [UIColor randomColor];
//        imageV.contentMode = UIViewContentModeScaleAspectFill;
//
//        NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,arr[j]];
//
//        [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
//
//        [self.scrollview addSubview:imageV];
//    }
    
}

-(UILabel *)labTakein{
    if (!_labTakein) {
        _labTakein = [[UILabel alloc]init];
        _labTakein.font = [UIFont systemFontOfSize:22];
        _labTakein.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:18];

    }
    return _labTakein;
}

-(UIView *)viewBack{
    if (!_viewBack) {
        _viewBack = [[UILabel alloc]init];
        [_viewBack setCornerRadiusWithRadius:15 isMasks:YES];
        [_viewBack setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:1];
        _viewBack.clipsToBounds = YES;
    }
    return _viewBack;
}

//- (UILabel *)viewText{
//    if (!_viewText) {
//        _viewText = [[UILabel alloc]init];
//        _viewText.numberOfLines = 0;
//        _viewText.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:13];
//
//
//    }
//    return _viewText;
//}

- (UIImageView *)Cardenter{
    if (!_Cardenter) {
        _Cardenter = [[UIImageView alloc]init];
        _Cardenter.image = [UIImage imageNamed:@"sku_更多货源报价"];
        
    }
    return _Cardenter;
}

- (UILabel *)price{
    if (!_price) {
        _price = [[UILabel alloc]init];
        _price.textColor = baseColorTheme;
//        _price.font = [UIFont systemFontOfSize:16];
        _price.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];

    }
    return _price;
}

//- (UIImageView *)merchantImage{
//    if (!_merchantImage) {
//        _merchantImage = [[UIImageView alloc]init];
//        _merchantImage.contentMode = 2;
//        [_merchantImage setCornerRadiusWithRadius:15 isMasks:YES];
//    }
//    return _merchantImage;
//}
//- (UILabel *)merchantName{
//    if (!_merchantName) {
//        _merchantName = [[UILabel alloc]init];
//        _merchantName.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:14];
//    }
//    return _merchantName;
//}

//- (BaseScrollView *)scrollview{
//    if (!_scrollview) {
//        _scrollview = [[BaseScrollView alloc]init];
//    }
//    return _scrollview;
//}

-(BaseImageV *)MapImage{
    if (!_MapImage) {
        _MapImage = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, kScreenW, 90) contentMode:2];
    }
    return _MapImage;
}

@end
